package modules.pathloss.model;

import tools.settings.Settings;

import datatypes.Antenna;
import tools.settings.SettingsMissingException;

/**
 *
 * @author Lynne Vandousselaere
 */
public class WI_LOS implements PathLossModel {

    //TODO add wilos plm verifysettings here
    private String[] snames = {"coverage_requirement", "indoor"};

    @Override
    public double[] getLogDistance(Settings settings, Antenna a)
            throws SettingsMissingException {
        if (!settings.contains(snames))
            throw SettingsMissingException.generate("PLM", "WI_LOS", snames);

        double f = a.getFrequency();
        float p = Float.parseFloat(settings.getSettingsValue("coverage_requirement"))/100;
        double s = Calculator.getShadowingMargin(a, settings, p);

        double[] mapl = new double[2];
        mapl[0] = 42.6 + (20 * Math.log10(f)) + s;
        mapl[1] = 26;

        return mapl;
    }

    public double getPathLoss(Settings settings, Antenna a, double distance)
            throws SettingsMissingException {
        if (!settings.contains(snames))
            throw SettingsMissingException.generate("PLM", "WI_LOS", snames);

        double f = a.getFrequency();
        float p = Float.parseFloat(settings.getSettingsValue("coverage_requirement")) /100;
        double d = distance / 1000; // to km.
        double s = Calculator.getShadowingMargin(a, settings, p);

        return 42.6 + (20 * Math.log10(f)) + (26 * Math.log10(d)) + s;
    }

    public String[] getRequiredSettingNames() {
        return snames;
    }
}
